﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using yu_dotnet.Models;

namespace yu_dotnet.Controllers
{
    [Route("yu/add")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        // GET api/values
        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult<string> Get(int id)
        {
            return "value";
        }
        private static Dictionary<string,AddRequest> DB=new Dictionary<string, AddRequest>();
        // POST api/values
        [HttpPost]
        public AddResponse Post([FromBody] AddRequest req)
        {
            AddResponse resp =new AddResponse();
            try{
                DB.Add(req.ISBN,req);
                resp.ISBN =req.ISBN;
                resp.message="交易成功了";
                resp.result="S";
            }
            catch(Exception ex){
                Console.WriteLine(ex);
                resp.ISBN ="";
                resp.message="交易失败了";
                resp.result="F";
            }
            return resp;
        }

        // PUT api/values/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/values/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
